package com.yuanzong.wuliu.service.business.customer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanzong.wuliu.common.vo.ApiResultPage;
import com.yuanzong.wuliu.mapper.business.customer.BusinessCustomerBaodanMapper;
import com.yuanzong.wuliu.model.business.customer.BusinessCustomerBaodan;
import com.yuanzong.wuliu.model.business.customer.bo.BusinessCustomerBaodanPageByMapperBo;
import com.yuanzong.wuliu.model.business.customer.query.*;
import com.yuanzong.wuliu.service.business.customer.IBusinessCustomerBaodanService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service("businessCustomerBaodanService")
public class BusinessCustomerBaodanServiceImpl extends ServiceImpl<BusinessCustomerBaodanMapper, BusinessCustomerBaodan> implements IBusinessCustomerBaodanService {

    // 逻辑删除
    protected static final boolean logicalDeleted = false;

    @Autowired
    private BusinessCustomerBaodanMapper businessCustomerBaodanMapper;

    //========================================================================================//
    // Service服务接口操作
    //========================================================================================//

    @Override
    public List<BusinessCustomerBaodan> querySubject(BusinessCustomerBaodanListQuery query) throws Exception {
        List<BusinessCustomerBaodan> businessCustomerBaodanList = null;
        QueryWrapper<BusinessCustomerBaodan> queryWrapper = new QueryWrapper<>();
        businessCustomerBaodanList = super.getBaseMapper().selectList(queryWrapper);
        return businessCustomerBaodanList;
    }

    @Override
    public ApiResultPage<BusinessCustomerBaodan> pageSubject(BusinessCustomerBaodanPageQuery query) throws Exception {
        ApiResultPage<BusinessCustomerBaodan> businessCustomerBaodanPageList = null;
        Page<BusinessCustomerBaodan> businessCustomerBaodanPage = new Page<>(query.getPageNum(), query.getPageSize());
        QueryWrapper<BusinessCustomerBaodan> queryWrapper = new QueryWrapper<>();
        if (query.getCustomerId() != null) {
            queryWrapper.eq("customer_id", query.getCustomerId());
        }
        if (query.getCustomerPhoneLike() != null) {
            queryWrapper.like("customer_phone", query.getCustomerPhoneLike());
        }
        if (query.getStatus() != null) {
            queryWrapper.eq("status", query.getStatus());
        }
        queryWrapper.orderByDesc("create_time");
        businessCustomerBaodanPage = super.baseMapper.selectPage(businessCustomerBaodanPage, queryWrapper);
        businessCustomerBaodanPageList = ApiResultPage.create(query.getPageNum(), query.getPageSize(), businessCustomerBaodanPage);
        return businessCustomerBaodanPageList;
    }

    @Override
    public ApiResultPage<BusinessCustomerBaodanPageByMapperBo> pageByMapper(BusinessCustomerBaodanPageQuery query) throws Exception {
        Page<BusinessCustomerBaodanPageByMapperBo> page = new Page<>(query.getPageNum(), query.getPageSize());
        page = businessCustomerBaodanMapper.pageByMapper(page, query);
        ApiResultPage<BusinessCustomerBaodanPageByMapperBo> apiResultPage = ApiResultPage.create(query.getPageNum(), query.getPageSize(), page);
        return apiResultPage;
    }

    //========================================================================================//
    // HTTP服务接口操作
    //========================================================================================//

    //========================================================================================//
    // extend methods
    //========================================================================================//


    //========================================================================================//
    // The end
    //========================================================================================//

}
